package com.ruoyi.web.controller.mall;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.Order;
import com.ruoyi.system.domain.vo.OrderDetailVo;
import com.ruoyi.system.domain.vo.OrderQueryVo;
import com.ruoyi.system.domain.vo.OrderUpdateVo;
import com.ruoyi.system.mapper.OrderMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController extends BaseController {

    @Resource
    private OrderMapper orderMapper;

    @GetMapping("/queryList")
    public TableDataInfo queryList(OrderQueryVo vo) {
        startPage();
        List<OrderDetailVo> list = orderMapper.queryList(vo);
        return getDataTable(list);
    }

    @GetMapping("/queryById/{id}")
    public AjaxResult queryById(@PathVariable Long id) {
        Order vo = orderMapper.selectById(id);
        return success(vo);
    }


    @PostMapping("/addTrackNo")
    public AjaxResult addTrackNo(@RequestBody OrderUpdateVo vo) {
        Order order = orderMapper.selectById(vo.getId());
        order.setTrackNo(vo.getTrackNo());
        if (order.getStatus()==2){
            order.setStatus(3);
        }
        orderMapper.updateById(order);
        return success();
    }



}
